function validateEnroll(action, elStatus, params) {
    var link = '/customer/' + action + 'Validate.action';
    new Ajax.Request(
            (link),
    {
        method: "get",
        parameters: params,
        requestHeaders: {Accept: 'application/json'},
        onSuccess:function(transport) {
            var jsonData = transport.responseText.evalJSON();
            var urlImg = '/img/i/process.png';
            var img = Element('img', {src: urlImg, alt: ''});
            elStatus.update(img);
            if ('error' == jsonData.result) {
                urlImg = '/img/i/warning.png';
            }
            if ('success' == jsonData.result) {
                urlImg = '/img/i/accept.png';
            }
            img.src = urlImg;
            img.alt = jsonData.message;
            elStatus.update(img);
        }
    }
            );
}

Position.Center = function(element, parent) {
    var w, h, pw, ph;
    var d = Element.getDimensions(element);
    w = d.width;
    h = d.height;
    //    Position.prepare();
    if (!parent) {
        var ws = windowSize();
        pw = ws[0];
        ph = ws[1];
    } else {
        pw = parent.offsetWidth;
        ph = parent.offsetHeight;
    }
    element.style.top = (ph / 2) - (h / 2) /*- Position.deltaY*/ + "px";
    element.style.left = (pw / 2) - (w / 2) /*- Position.deltaX */ + "px";
};
function windowSize() {
    var winW = 0, winH = 0;
    if (parseInt(navigator.appVersion) > 3) {
        if (navigator.appName == "Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft") != -1) {
            winW = document.body.offsetWidth;
            winH = document.body.offsetHeight;
        }
    }
    return [winW, winH];
}


var JdsmBlock = Class.create({
    initialize:function(id) {
        this.block = new Element('div', {id: id});
        this.id = id;
    },
    getId: function() {
        return this.id;
    },
    setId: function(newId) {
        this.id = newId;
    },
    getContent: function() {
        return this.block.innerHTML;
    },
    setContent:function(content) {
        this.block.innerHTML = content;
    },
    setWidth: function(width) {
        this.block.style.width = width;
    },
    setHeight: function(height) {
        this.block.style.height = height;
    },
    getWidth: function() {
        return this.block.style.width;
    },
    getHeight: function() {
        return this.block.style.height;
    },
    getElement: function() {
        return this.block;
    }
});

var JdsmWindow = Class.create(JdsmBlock, {
    initialize:function($super, id) {
        $super(id);
    },
    showCenter: function() {
        this.getElement().setStyle(
        {
            position:'absolute',
            background: '#ffffff',
            border:'solid 1px #cccccc',
            zindex: 4
        });
        Position.Center(this.getElement());
    }

});

var JdsmHeader = Class.create(JdsmBlock, {
    initialize:function($super, id) {
        $super(id);
        this.title = "";
        this.getElement().setAttribute('class', 'windowHeaderClass');
    },
    getTitle:function() {
        return this.title;
    },
    setTitle: function(title) {
        this.title = title;
    }
});

var JdsmWindowHeader = Class.create(JdsmWindow, {
    initialize:function($super, id) {
        $super(id);
        this.mainContent = new JdsmBlock(id + '_container');
        this.title = new JdsmHeader(id + '_header');
        Insertion.Top(this.getElement(), this.mainContent.getElement());
        Insertion.Top(this.getElement(), this.title.getElement());
    },
    setContent: function(content) {
        this.mainContent.setContent(content);
    },
    getContent: function() {
        return this.mainContent.getContent();
    },
    getContainer: function() {
        return this.mainContent;
    },
    getHeader: function() {
        return this.title;
    },
    getTitle: function() {
        return this.title.getElement.innerHTML;
    },
    setTitle: function(title) {
        this.title.getElement().innerHTML = title;
    }
});

var JdsmCloseWindowHeader = Class.create(JdsmWindowHeader, {
    initialize:function($super, id) {
        $super(id);
        /*        this.header = new JdsmWindowHeaderClose('header' + id);
         this.container = new JdsmBlock('block' + id);
         this.error = new Element('div', {id: 'windowError'});
         this.getElement().appendChild(this.header.getElement());
         this.getElement().appendChild(this.error);
         this.getElement().appendChild(this.container.getElement());


         var el = this.getElement();
         Insertion.Top(document.body, el);
         Event.observe(this.header.getCloseButton(), 'click', function() {
         Element.remove(el);
         });
         */

        this.id = id;
        this.img = new Element('img', {alt:'', src:'/img/i/delete.png'});
        Element.setStyle(this.img, {float:'right'});
        this.header = this.getHeader();
        this.getHeader().setHeight('16px');
        this.getHeader().setWidth(this.getWidth());
        Insertion.Top(this.getHeader().getElement(), this.img);

        Event.observe(this.img, 'click', function() {
            Element.remove($(id));
        });
        new Draggable(this.getElement(), {handle:(this.header.getElement())});

    },
    setTitle: function(title) {
        var el = $(this.id + '_header');
        el.innerHTML = '';
//        el.appendChild(this.img);

        Insertion.Top(el, title);
        Insertion.Top(el, this.img);
    },
    getImgCloseButton: function() {
        return this.img;
    }
});

function showPopupCenter() {
    var win = new JdsmCloseWindowHeader('testId');
    Insertion.Top(document.body, win.getElement());
    win.setTitle("test title");
    win.setTitle("test title2");
    win.setContent("content <b>text</b> value");
    win.setWidth("100px");
    win.setHeight("60px");
    win.showCenter();
}

function showLoginPage(titleMessage) {
    var win = $('winid');
    if (!win) {
        new Ajax.Request(
                ( "/utils/loginpage.action"),
        {
            method: "get",
            evalScripts: true,
            onSuccess:function(transport) {
                var xhtmlData = transport.responseText;
                var w = new JdsmWindowWithHeader('winid');
                w.setContent(xhtmlData);
                w.setTitle(titleMessage);
                w.showCenter();
            }
        }
                );
    } else {
        if (win.style.display == 'none') {
            win.style.display = '';
        }
        Effect.Pulsate(win);
    }
}

function loginProcess() {
    $('loginForm').request({
        method:'post',
        onComplete:function(transport) {
            var response = transport.responseText;
            if (response == 'success') {
                Effect.Shrink($('winid'), {
                    afterUpdateInternal:function() {
                        window.location.href = '/index.action';
                    }
                });

            } else {
                $('windowError').innerHTML = response;
            }
        }
    });
}


